package com.takeoutsystem.config;

import com.takeoutsystem.interceptor.AdminLoginInterceptor;
import com.takeoutsystem.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * web服务配置类
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    AdminLoginInterceptor adminLoginInterceptor;

    /**
     * 添加验证登录状态的拦截器
     * @param registry 拦截器注册中心
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/wx/**","/css/**","/js/**","/fonts/**","/images/**","/favicon.ico","/admin/**","/error/**","/error");
        registry.addInterceptor(adminLoginInterceptor)
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/admin/login","/admin/doLogin","/admin/captcha","/error/**","/error");

    }
}
